﻿using System;
using IcicleFramework.Entities;
using Microsoft.Xna.Framework;

namespace IcicleFramework.Components.Actions.Movement
{
    public class DirectAngularMovementAction : DirectMovementAction
    {
        public float MoveSpeed { get; set; }

        public float Angle { get; set; }

        public DirectAngularMovementAction() { }

        public DirectAngularMovementAction(DirectAngularMovementAction old)
            : base(old)
        { }

        public override void Execute(IGameObject target, IActionData data = null, bool continuous = false)
        {
            base.Execute(target, data, continuous);

            //Pull out the action data that we need. We're looking for a movespeed and angle.
            if (data != null && data.Data.ContainsKey("moveSpeed"))
            {
                MoveSpeed = (float)data.Data["moveSpeed"];
            }

            if (data != null && data.Data.ContainsKey("angle"))
            {
                Angle = (float)data.Data["angle"];
            }

            var scaleX = (float)Math.Cos(Math.PI / 180.0 * Angle);
            var scaleY = (float)Math.Sin(Math.PI / 180.0 * Angle);

            MovementAmount = new Vector2(scaleX * MoveSpeed, scaleY * MoveSpeed);
        }

        public override IAction DeepClone()
        {
            return new DirectAngularMovementAction(this);
        }
    }
}
